#ifndef _DIRECT_X_3D_
#define _DIRECT_X_3D_

#include <d3d9.h>
#include <d3dx9.h>

#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
#pragma comment(lib, "dxguid.lib")

typedef unsigned char uChar;

class Direct3D
{
private:

	LPDIRECT3D9				m_lpDirect3DObj;
	LPDIRECT3DDEVICE9		m_lpDirect3DDev;
	LPD3DXSPRITE			m_lpSprite;
	LPD3DXLINE				m_lpLine;
	D3DPRESENT_PARAMETERS	m_dppPresentParams;
	HWND					m_hWnd;
	static Direct3D			m_siInstance;

	Direct3D();
	Direct3D(Direct3D &instance);
	Direct3D& operator =(Direct3D &instance);

public:

	~Direct3D();

	///////////////////////////////////////////////////////////////////////////////////////
	//	Function:		GetInstance
	//
	//	Last Modified:	03/05/2011
	//
	//	Parameter(s):	void
	//
	//	Return:			A pointer to the instance of the class.
	//
	//	Purpose:		Returns a pointer to the single instance.
	//
	static Direct3D* GetInstance();

	///////////////////////////////////////////////////////////////////////////////////////
	//	Function:		Accessors
	//
	//	Last Modified:	03/05/2011
	//
	LPDIRECT3D9			GetD3DObject();
	LPDIRECT3DDEVICE9	GetD3DDevice();
	LPD3DXSPRITE		GetSprite();
	LPD3DXLINE			GetLine();
	const D3DPRESENT_PARAMETERS* GetParams();

	///////////////////////////////////////////////////////////////////////////////////////
	//	Function:		Initalize
	//
	//	Last Modified:	03/05/2011
	//
	//	Parameter(s):	hWnd			A handle to the window to initialize
	//									Direct3D in.
	//					screenWidth		The width to initalize the window to.
	//					screenHeight	The height to initalize the window to.
	//					windowMode		The screen mode to initialize the window to.
	//					vsyncOn			Determines if the window has vsynced display mode
	//									on or off.
	//
	//	Return:			True if it was successful.
	//
	//	Purpose:		Initalizes the D3DObject.
	//
	bool Initalize(HWND hWnd, int screenWidth, int screenHeight, bool windowMode = true, bool VsyncOn = true);
	
	///////////////////////////////////////////////////////////////////////////////////////
	//	Function:		Shutdown
	//
	//	Last Modified:	03/05/2011
	//
	//	Parameter(s):	void
	//
	//	Return:			void
	//
	//	Purpose:		Shuts down the D3DObject.
	//
	void Shutdown();

	///////////////////////////////////////////////////////////////////////////////////////
	//	Function:		ScreenClear
	//
	//	Last Modified:	03/05/2011
	//
	//	Parameter(s):	red		The amount of red to clear the screen to.
	//					blue	The amount of blue to clear the screen to.
	//					green		The amount of green to clear the screen to.
	//
	//	Return:			void
	//
	//	Purpose:		Clears the screen to the given color.
	//
	void ScreenClear(uChar red = 0, uChar blue = 0, uChar green = 0);

	///////////////////////////////////////////////////////////////////////////////////////
	//	Function:		DeviceBegin
	//
	//	Last Modified:	03/05/2011
	//
	//	Parameter(s):	void
	//
	//	Return:			Returns true if it's successful.
	//
	//	Purpose:		Starts the device for rendering.
	//
	bool DeviceBegin();

	///////////////////////////////////////////////////////////////////////////////////////
	//	Function:		SpriteBegin
	//
	//	Last Modified:	03/05/2011
	//
	//	Parameter(s):	void
	//
	//	Return:			Returns true if it's successful.
	//
	//	Purpose:		Starts the sprite for rendering.
	//
	bool SpriteBegin();

	///////////////////////////////////////////////////////////////////////////////////////
	//	Function:		LineBegin
	//
	//	Last Modified:	03/05/2011
	//
	//	Parameter(s):	void
	//
	//	Return:			Returns true if it's successful.
	//
	//	Purpose:		Starts the sprite for rendering.
	//
	bool LineBegin();

	///////////////////////////////////////////////////////////////////////////////////////
	//	Function:		DeviceEnd
	//
	//	Last Modified:	03/05/2011
	//
	//	Parameter(s):	void
	//
	//	Return:			Returns true if it's successful.
	//
	//	Purpose:		Ends the device for rendering.
	//
	bool DeviceEnd();

	///////////////////////////////////////////////////////////////////////////////////////
	//	Function:		SpriteEnd
	//
	//	Last Modified:	03/05/2011
	//
	//	Parameter(s):	void
	//
	//	Return:			Returns true if it's successful.
	//
	//	Purpose:		Ends the sprite for rendering.
	//
	bool SpriteEnd();

	///////////////////////////////////////////////////////////////////////////////////////
	//	Function:		LineEnd
	//
	//	Last Modified:	03/05/2011
	//
	//	Parameter(s):	void
	//
	//	Return:			Returns true if it's successful.
	//
	//	Purpose:		Ends the line for rendering.
	//
	bool LineEnd();

	///////////////////////////////////////////////////////////////////////////////////////
	//	Function:		Present
	//
	//	Last Modified:	03/05/2011
	//
	//	Parameter(s):	void
	//
	//	Return:			void
	//
	//	Purpose:		Renders the back buffer to the screen.
	//
	void Present();

	///////////////////////////////////////////////////////////////////////////////////////
	//	Function:		ChangeParameters
	//
	//	Last Modified:	03/05/2011
	//
	//	Parameter(s):	width		The width to change the screen to.
	//					height		The height to change the screen to.
	//					windowMode	The mode to change the window to.
	//
	//	Return:			void
	//
	//	Purpose:		Changes the display parameters of the screen.
	//
	void ChangeParameters(int width, int height, bool windowMode);

	///////////////////////////////////////////////////////////////////////////////////////
	//	Function:		DrawRect
	//
	//	Last Modified:	03/05/2011
	//
	//	Parameter(s):	rect		The rectangle used to draw.
	//					red			The amount of red to draw the rectangle.
	//					blue		The amount of blue to draw the rectangle.
	//					green		The amount of green to draw the rectangle.
	//
	//	Return:			void
	//
	//	Purpose:		Draws a rectangle of the specified color.
	//
	void DrawRect(RECT rect, uChar red, uChar blue, uChar green);

	///////////////////////////////////////////////////////////////////////////////////////
	//	Function:		DrawLine
	//
	//	Last Modified:	03/05/2011
	//
	//	Parameter(s):	x1			The x of the starting point.
	//					y1			The y of the starting point.
	//					x2			The x of the ending point.
	//					y2			The y of the ending point.
	//					red			The amount of red to draw the rectangle.
	//					blue		The amount of blue to draw the rectangle.
	//					green		The amount of green to draw the rectangle.
	//
	//	Return:			void
	//
	//	Purpose:		Draws a line of the specified color.
	//
	void DrawLine(int x1, int y1, int x2, int y2, uChar red, uChar blue, uChar green);
};

#endif // _DIRECT_X_2D_